﻿#ifndef DIALOG_H
#define DIALOG_H

#include <QWidget>
#include <QTimer>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QPointer>
#include <QCloseEvent>

#include "QtScrcpyCore/adbprocess.h"
#include "QtScrcpyCore/QtScrcpyCore.h"

namespace Ui {
class Dialog;
}

class Dialog : public QWidget
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = nullptr);
    ~Dialog();

    void outLog(const QString & log, bool newLine = true);
    bool filterLog(const QString & log);
    void getIPbyIp(void);

private slots:
    void slotActivated(QSystemTrayIcon::ActivationReason reason);

    void on_usbConnectBtn_clicked();
    void on_stopAllServerBtn_clicked();
    void on_useSingleModeCheck_clicked();
    void on_updateDevice_clicked();
    void on_wifiConnectBtn_clicked();
    void on_getIPBtn_clicked();
    void on_startAdbdBtn_clicked();
    void on_wirelessConnectBtn_clicked();

    void on_startServerBtn_clicked();

private:
    void initUI();
    void updateBootConfig(bool toView = true);
    void delayMs(int ms);
    int findDeviceFromeSerialBox(bool wifi);
    bool checkAdbRun(void);
    quint32 getBitRate(void);

    QString getGameScript(const QString &fileName);
    const QString &getServerPath(void);

protected:
    void closeEvent(QCloseEvent * event);

private:
    Ui::Dialog *ui;
    QTimer m_autoUpdatetimer;
    qsc::AdbProcess m_adb;

    QSystemTrayIcon * m_hideIcon;
    QMenu * m_menu;
    QAction * m_showWindow;
    QAction * m_quit;
};

#endif // DIALOG_H
